float value;
int t;
double vel;
 

void setup()
 {
   Serial.begin(9600);
   pinMode(A0,INPUT);
   pinMode(4,OUTPUT);
 }
 

void loop() 
 {
   value = analogRead(A0);
   t = 250;
   double distance1;
    distance1 = 7.84E-9*pow(value,4)-(1.25E-5)*pow(value,3) +0.00741*pow(value,2)- 2.034*value+ 254.7;
    if(distance1<100)
    {
     delay(t);
     value = analogRead(A0);
    double distance2;
    distance2 = 7.84E-9*pow(value,4)-(1.25E-5)*pow(value,3) +0.00741*pow(value,2)- 2.034*value+ 254.7;
  //Serial.println(distance);
  vel=(distance2-distance1)*4;
  if(vel>30||vel<-30)
    digitalWrite(4,HIGH);
    
   Serial.println(vel);
  delay(t);
    }
 }

 
